package app.controllers.mobileweb;

import app.Const;
import app.interceptors.MobileWxMemberInterceptor;
import app.models.gift.Exchange;
import app.models.gift.Gift;
import app.models.member.Member;
import com.github.sog.controller.BasicController;
import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

/**
 * <p>
 * .
 * </p>
 *
 * @author Jerry Ou
 * @version 1.0 2014-05-28 11:28
 * @since JDK 1.6
 */
@Before(MobileWxMemberInterceptor.class)
public class GiftController extends BasicController {

    public void index() {
        long mid = getParaToLong(Const.MEMBER_PARAM, 0l);
        Member member = Member.dao.findById(mid);

        List<Gift> gifts = Gift.dao.findByStatus(true);

        setAttr("gifts", gifts);

        setAttr("member", member);
        render("index.ftl");
    }

    public void item() {
        long mid = getParaToLong(Const.MEMBER_PARAM, 0l);
        long id = getParaToLong("id", 0l);
        Member member = Member.dao.findById(mid);

        Gift gift = Gift.dao.findById(id);

        setAttr("gift", gift);
        setAttr("member", member);
        render("item.ftl");
    }

    public void mine() {
        long mid = getParaToLong(Const.MEMBER_PARAM, 0l);

        boolean status = getParaToBoolean("status", false);

        List<Record> mines = Exchange.dao.findMineByStatus(mid, status);

        setAttr("mines", mines);
        setAttr("status", status);

        render("mine.ftl");
    }

}
